import 'package:boss/color_constant.dart';
import 'package:boss/models/commodity.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/commodity/categories/page/plusCommodityMode/page/plusPackage/widget/package_panel.dart';
import 'package:boss/ui/page/takeoutManagement/page/packagingFeeSetting/provider/package_provider.dart';
import 'package:boss/ui/widget/label_button.dart';
import 'package:boss/ui/widget/picker/commodityPicker/commodity_picker.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PackagingWithoutCommodityPanel extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return PackagePanel(
      title: '不参与包装盒菜品',
      titleStyle: TextStyle(
        fontSize: 32.sp,
        color: ColorConstant.ff33,
        fontWeight: FontWeight.w500,
      ),
      actions: <Widget>[
        LabelButton(
          title: '+选择菜品',
          textStyle: TextStyleConstant().blue_28,
          onTap: () async {
            final provider = Provider.of<PackageProvider>(
              context,
              listen: false,
            );
            final selected = provider.data.commodityFormList
                .map((item) => Commodity.fromJson({
                      'id': item.commodityId,
                      'sku': {
                        'skuId': item.skuId,
                      }
                    }))
                .toList();
            final res = await showCommodityPicker(
              context,
              selectedCommodities: selected,
              isShowSku: true,
            );

            if (res != null) {
              provider.setCommoditys(res);
            }
          },
        )
      ],
      children: <Widget>[
        Consumer<PackageProvider>(
          builder: (context, provider, _) => Text(
            provider.data.commodityName,
            style: TextStyleConstant().normal_1_28,
          ),
        ),
      ],
    );
  }
}
